package com.atguigu.srb.core.controller.admin;


import com.atguigu.common.result.R;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.query.UserInfoQuery;
import com.atguigu.srb.core.service.UserInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author 杜佳佳
 * @since 2021-04-13
 */
@Api(tags = "会员管理")
@RestController
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation("会员分页条件查询")
    @PostMapping("queryPage/{page}/{limit}")
    public R queryPage(@PathVariable("page") Long page, @PathVariable("limit") Long limit, @RequestBody UserInfoQuery userInfoQuery) {
        Page<UserInfo> pages = new Page<>(page,limit);

        IPage<UserInfo> pageModel = userInfoService.listPage(pages,userInfoQuery);

        return R.ok().data("data",pageModel);

    }

    @ApiOperation("会员状态锁定或者解锁")
    @GetMapping("/lock/{id}/{status}")
    public R lock(@PathVariable("id") Long id,@PathVariable("status") Integer status) {
        userInfoService.lock(id,status);
        return R.ok().message(status == 1 ? "解锁成功":"锁定成功");
    }
}

